package com.david.IfaceAutoTest.entity;

import com.david.IfaceAutoTest.enums.ResultCode;
import lombok.Data;

/**
 * @author David
 * http请求返回的最外层对象
 */
/**
 * 返回通用结果集对象
 */
@Data
public class CommonResult<T> {
    private long code;
    private String message;
    private T data;

    protected CommonResult() {
    }

    protected CommonResult(long code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public CommonResult(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    /**
     * 成功返回结果
     *
     * @param data 获取的数据
     */
    public static <T> CommonResult<T> success(T data) {
        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage(), data);
    }

    /**
     * 成功返回结果
     *
     * @param data    获取的数据
     * @param message 提示信息
     */
    public static <T> CommonResult<T> success(T data, String message) {
        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), message, data);
    }

    /**
     * 成功返回结果
     */
    public static <T> CommonResult<T> success() {
        String c=ResultCode.SUCCESS.getCode()+"";
        String m=ResultCode.SUCCESS.getMessage();
        return new CommonResult<T>(ResultCode.SUCCESS.getCode(), ResultCode.SUCCESS.getMessage());
    }

    public static <T> CommonResult<T> failed(Integer code, String message) {
        return new CommonResult<T>(code, message);
    }
    /**
     * 失败返回结果
     *
     * @param message 提示信息
     */
    public static <T> CommonResult<T> failed(String message) {
        return new CommonResult<T>(ResultCode.FAILED.getCode(), message);
    }

    /**
     * 失败返回结果
     */
    public static <T> CommonResult<T> failed() {
        return new CommonResult<T>(ResultCode.FAILED.getCode(), ResultCode.FAILED.getMessage());
    }


    /**
     * 参数验证失败返回结果
     *
     * @param message 提示信息
     */
    public static <T> CommonResult<T> validateFailed(String message) {
        return new CommonResult<T>(ResultCode.VALIDATE_FAILED.getCode(), message);
    }

    /**
     * 未登录返回结果
     */
    public static <T> CommonResult<T> unauthorized(T data) {
        return new CommonResult<T>(ResultCode.UNAUTHORIZED.getCode(), ResultCode.UNAUTHORIZED.getMessage(), data);
    }

    /**
     * 未授权返回结果
     */
    public static <T> CommonResult<T> forbidden(T data) {
        return new CommonResult<T>(ResultCode.FORBIDDEN.getCode(), ResultCode.FORBIDDEN.getMessage(), data);
    }

    /**
     * 成功返回结果
     *
     * @param data 接口执行结果
     */
    public static <T> CommonResult<T> run_success(T data) {
        return new CommonResult<T>(ResultCode.RUN_SUCCESS.getCode(), ResultCode.RUN_SUCCESS.getMessage(), data);
    }

    /**
     * 成功返回结果
     *
     * @param data    接口执行结果
     * @param message 提示信息
     */
    public static <T> CommonResult<T> run_success(T data, String message) {
        return new CommonResult<T>(ResultCode.RUN_SUCCESS.getCode(), message, data);
    }

    /**
     * 成功返回结果
     */
    public static <T> CommonResult<T> run_success() {
        return new CommonResult<T>(ResultCode.RUN_SUCCESS.getCode(), ResultCode.RUN_SUCCESS.getMessage());
    }

    /**
     * 成功返回结果
     *
     * @param data 接口执行结果
     */
    public static <T> CommonResult<T> run_failed(T data) {
        return new CommonResult<T>(ResultCode.RUN_FAILED.getCode(), ResultCode.RUN_FAILED.getMessage(), data);
    }

    /**
     * 成功返回结果
     *
     * @param data    接口执行结果
     * @param message 提示信息
     */
    public static <T> CommonResult<T> run_failed(T data, String message) {
        return new CommonResult<T>(ResultCode.RUN_FAILED.getCode(), message, data);
    }

    /**
     * 成功返回结果
     */
    public static <T> CommonResult<T> run_failed() {
        return new CommonResult<T>(ResultCode.RUN_FAILED.getCode(), ResultCode.RUN_FAILED.getMessage());
    }
}
